//
//  KFDPreferentialActivitiesViewCell.m
//  KFD
//
//  Created by JIRENTIANXIANG on 6/30/15.
//  Copyright © 2015 kfd. All rights reserved.
//

#import "KFDPreferentialActivitiesViewCell.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "NSDate+format.h"
#import "ui_config.h"
#import "KFDClient.h"

@interface KFDPreferentialActivitiesViewCell ()

@property (weak, nonatomic) IBOutlet UIImageView *thumbnail;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UIButton *joinButton;

@end

@implementation KFDPreferentialActivitiesViewCell

- (void)awakeFromNib {
    // Initialization code
    self.thumbnail.contentMode=UIViewContentModeScaleToFill;
    [self.joinButton setTitleColor:KFD_WHITE forState:UIControlStateNormal];
    self.joinButton.backgroundColor=KFD_GREEN;
    self.joinButton.layer.cornerRadius=4;
}

- (IBAction)joinButtonPressed:(id)sender {
    KFDClient* client=[KFDClient sharedClient];
    [client joinPreferentialActivity:self.activity.id successHandler:^{
        if (self.joinButtonAction) {
            dispatch_async(dispatch_get_main_queue(), ^{
                self.joinButtonAction(YES,nil);
            });
        }
    } failureHandler:^(KFDResponseBody *response) {
        if (self.joinButtonAction) {
            dispatch_async(dispatch_get_main_queue(), ^{
                self.joinButtonAction(NO,response.message);
            });
        }
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setActivity:(KFDPreferentialActivity *)activity
{
    _activity=activity;
    [self.thumbnail sd_setImageWithURL:[NSURL URLWithString:activity.thumb]];
    self.contentLabel.text=activity.title;
    self.dateLabel.text=[NSString stringWithFormat:@"开始时间 : %@",activity.starttime.year_month_day];
}

@end
